package com.likou;

/**
 * Author: 陈桂明
 * Date: 2025/9/9 14:57
 * Description: q108
 */
public class q108 {

    public TreeNode sortedArrayToBST(int[] nums) {
        return insert(0, nums.length - 1, nums);
    }

    private TreeNode insert(int left, int right, int[] nums) {
        if (left > right) {
            return null;
        }

        int mid = (left + right) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = insert(left, mid - 1, nums);
        root.right = insert(mid + 1, right, nums);
        return root;
    }
}
